<?php
namespace App\Repositories\GameServer;

use App\Models\GameServer\Channel;

/**
* 渠道商
*/
class ChannelRepository
{

    public function getChannels($where = null)
    {
        return Channel::when($where, function($query) use ($where) {
                            return $query->whereIn('distributer_id', $where);
                        })
                        ->orderBy('id', 'desc')->get();
    }

    public function getChannel($id)
    {
        return Channel::find($id);
    }

    public function addChannel($request)
    {
        $params = $request->all();
        $params['password'] = password_hash('123456', PASSWORD_DEFAULT);

        $channel = Channel::create($params);

        return $channel;
    }

    public function updateChannel($request, $id)
    {
        Channel::findOrFail($id)->update($request->all());

        return true;
    }

    public function deleteChannel($id)
    {
        Channel::destroy($id);

        return true;
    }

    public function editStatus($id, $status)
    {
        Channel::findOrFail($id)->update(['status' => $status]);

        return true;
    }
}